package com.rwdesign.springboot.Waimai.utils;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * @author rystart
 * @create 2022-01-29
 */
@Data
public class ResultBody {
    // 是否成功
    private Boolean success;

    // 返回码
    private Integer status;

    // 返回信息
    private String message;

    // 返回数据
    private Map<String, Object> data = new HashMap<String, Object>();
    /**
     * 请求成功
     * @return ResultBody
     */
    public static ResultBody isOk(Object...okResult){
        ResultBody resultBody = new ResultBody();
        resultBody.setSuccess(true);
        resultBody.setStatus((Integer) okResult[0]);
        resultBody.setMessage((String) okResult[1]);
        if(okResult.length==3){
            resultBody.setData((Map<String, Object>) okResult[2]);
        }
        return resultBody;
    }

    /**
     * 请求失败
     * @return ResultBody
     */
    public static ResultBody isError(Object...errorResult){
        ResultBody resultBody = new ResultBody();
        resultBody.setSuccess(false);
        resultBody.setStatus((Integer) errorResult[0]);
        resultBody.setMessage((String) errorResult[1]);
        if(errorResult.length==3){
            resultBody.setData((Map<String, Object>) errorResult[2]);
        }
        return resultBody;
    }
}
